define([ "app" ], function(app) {
	var deps = [ "$http", "BaseService" ];

	function resource($http, BaseService) {
		return initSpaceResource($http, BaseService.restfulUrl + "permission/");
	}
	var postHeader = {
		"Content-Type" : "application/x-www-form-urlencoded;charset=utf-8"
	};
	function initSpaceResource($http, baseUrl) {
		return {
			/**
			 * 任务权限列表
			 * 
			 */
			queryTaskCreationOrgs : function(pageNum, pageSize) {
				return $http.post(baseUrl + 'queryTaskCreationOrgs', {
					pageNo : pageNum,
					pageSize : pageSize
				}, {
					headers : postHeader
				});
			},
			
			/**
			 * 设置任务权限 新增、删除
			 * 
			 * @param orgIds 组织ID
			 * @param type 0 新增 1删除
			 * 
			 * @returns {*|Object}
			 */
			grantTaskCreation : function(orgIds, type) {
				return $http.post(baseUrl + "grantTaskCreation", {
					orgIds : angular.isArray(orgIds) ? orgIds : [orgIds],
					type : type
				}, {
					headers : postHeader
				});
			},
			
			/**
			 *  查看群组创建人列表
			 */
			queryGroupCreationUsers : function(pageNum, pageSize) {
				return $http.post(baseUrl + 'queryGroupCreationUsers', {
					pageNo : pageNum,
					pageSize : pageSize
				}, {
					headers : postHeader
				});
			},
			
			/**
			 * 群组管理员 新增、删除
		 	 * @param orgIds 组织ID
			 * @param type 0 新增 1删除
			 */
			grantGroupCreation : function(userIds, type) {
				return $http.post(baseUrl + "grantGroupCreation", {
					userIds : angular.isArray(userIds) ? userIds : [userIds],
					type : type
				}, {
					headers : postHeader
				});
			},
			
			/**
			 * 查询 通讯录权限 
			 */
			queryOrgPermission : function(orgId, pageNum, pageSize) {
				return $http.post(baseUrl + 'queryOrgPermission', {
					orgId : orgId,
					pageNo : pageNum,
					pageSize : pageSize
				}, {
					headers : postHeader
				});
			},
			
			grantOrgPermission : function(orgId, selectedOrgIds) {
				return $http.post(baseUrl + "grantOrgPermission", {
					orgId : orgId,
					selectedOrgIds : selectedOrgIds
				}, {
					headers : postHeader
				});
			},
			/**
			 * 删除
			 */
			delOrgPermission : function(orgId, selectedOrgIds){
				return $http.post(baseUrl + "delOrgPermission", {
					orgId : orgId,
					selectedOrgIds : selectedOrgIds
				}, {
					headers : postHeader
				});
			},
			
			queryChannelCreationUsers : function(pageNum, pageSize) {
				return $http.post(baseUrl + 'queryChannelCreationUsers', {
					pageNo : pageNum,
					pageSize : pageSize
				}, {
					headers : postHeader
				});
			},
			/**
			 * 资讯号 增删
			 */
			grantChannelCreation : function(userIds, type) {
				return $http.post(baseUrl + "grantChannelCreation", {
					userIds : angular.isArray(userIds) ? userIds : [userIds],
					type : type
				}, {
					headers : postHeader
				});
			},
		};
	}
	resource.$inject = deps;
	app.lazy.factory("PermissionResource", resource);
});